<template>
    <div>
        <div id="login">
            <el-form :model="loginVo" status-icon :rules="loginRules" ref="ruleForm"  label-width="80px" class="demo-loginVo" id="loginVo">
                <el-form-item label="邮箱:" prop="email">
                    <el-input type="text" v-model="loginVo.email" autocomplete="off" style="width: 300px"></el-input>
                </el-form-item>
                <el-form-item label="密码:" prop="password">
                    <el-input type="password" v-model="loginVo.password" autocomplete="off" style="width: 300px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="login()" class="mybt">登录</el-button>
                    <el-button type="primary"  class="mybt">注册</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                loginVo:{"email":"",
                        "password":""},
                loginRules:{
                    email:[
                        { required: true, message: '请输入邮箱', trigger: 'blur' },
                    ],
                    password:[
                        { required: true, message: '请输入密码', trigger: 'blur' },
                    ]
                }
            }
        },
        methods:{
            login(){
                this.$http.post("http://localhost:8090/user/login",this.loginVo).then(resp=>{
                    if (resp.data.code==2000){
                        //获取响应的token，保存到localStorage
                        localStorage.setItem("token",resp.data.data);
                        //路由跳转
                        this.$router.push("/home")
                    }else{
                        this.$message.error("账号或密码错误");
                    }
                })
            }
        }
    }
</script>

<style>
    #login{
        width: 420px;
        height: 300px;
        margin: 50px auto;
        background-color: #ffffff;
        opacity:0.8;
    }
    #text{
        padding-left: 140px ;
        padding-top: 40px;
        border-bottom: 3px solid #0b2e13;
    }
    .mybt{
        margin-right: 90px;
    }
</style>